package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyMaterialOtherItem;
import com.ruoyi.buy.service.IBuyMaterialOtherItemService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 材料清单明细-替代Controller
 * 
 * @author ruoyi
 * @date 2024-02-20
 */
@RestController
@RequestMapping("/buy/materialOtherItem")
public class BuyMaterialOtherItemController extends BaseController
{
    @Autowired
    private IBuyMaterialOtherItemService buyMaterialOtherItemService;

    /**
     * 查询材料清单明细-替代列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BuyMaterialOtherItem buyMaterialOtherItem)
    {
        startPage();
        List<BuyMaterialOtherItem> list = buyMaterialOtherItemService.selectBuyMaterialOtherItemList(buyMaterialOtherItem);
        return getDataTable(list);
    }

    /**
     * 导出材料清单明细-替代列表
     */

    @Log(title = "材料清单明细-替代", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyMaterialOtherItem buyMaterialOtherItem)
    {
        List<BuyMaterialOtherItem> list = buyMaterialOtherItemService.selectBuyMaterialOtherItemList(buyMaterialOtherItem);
        ExcelUtil<BuyMaterialOtherItem> util = new ExcelUtil<BuyMaterialOtherItem>(BuyMaterialOtherItem.class);
        util.exportExcel(response, list, "材料清单明细-替代数据");
    }

    /**
     * 获取材料清单明细-替代详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buyMaterialOtherItemService.selectBuyMaterialOtherItemById(id));
    }

    /**
     * 新增材料清单明细-替代
     */

    @Log(title = "材料清单明细-替代", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyMaterialOtherItem buyMaterialOtherItem)
    {
        return toAjax(buyMaterialOtherItemService.insertBuyMaterialOtherItem(buyMaterialOtherItem));
    }

    /**
     * 修改材料清单明细-替代
     */

    @Log(title = "材料清单明细-替代", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyMaterialOtherItem buyMaterialOtherItem)
    {
        return toAjax(buyMaterialOtherItemService.updateBuyMaterialOtherItem(buyMaterialOtherItem));
    }

    /**
     * 删除材料清单明细-替代
     */

    @Log(title = "材料清单明细-替代", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buyMaterialOtherItemService.deleteBuyMaterialOtherItemByIds(ids));
    }
}
